

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>分布式文件系统之上的应用程序最佳实践 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="FS 卷和子卷" href="../fs-volumes/" />
    <link rel="prev" title="NFS" href="../nfs/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../">Ceph 文件系统</a></li>
      <li class="breadcrumb-item active">分布式文件系统之上的应用程序最佳实践</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../_sources/cephfs/app-best-practices.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id4">管理</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../createfs/"> 创建 CephFS 文件系统</a></li>
<li class="toctree-l3"><a class="reference internal" href="../administration/"> 管理命令</a></li>
<li class="toctree-l3"><a class="reference internal" href="../multifs/"> 创建多个文件系统</a></li>
<li class="toctree-l3"><a class="reference internal" href="../add-remove-mds/"> 配备、增加、删除 MDS</a></li>
<li class="toctree-l3"><a class="reference internal" href="../standby/">术语</a></li>
<li class="toctree-l3"><a class="reference internal" href="../standby/#mds">MDS 守护进程的引用</a></li>
<li class="toctree-l3"><a class="reference internal" href="../standby/#id3">故障切换的管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../standby/#standby-replay">热备（ standby-replay ）的配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../standby/#mds-join-fs">配置 MDS 与文件系统的亲和性</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cache-configuration/"> MDS 缓存配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mds-config-ref/"> MDS 配置选项</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../man/8/ceph-mds/"> ceph-mds 手册页</a></li>
<li class="toctree-l3"><a class="reference internal" href="../nfs/"> 通过 NFS 导出</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> 应用最佳实践</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#ls-l">ls -l</a></li>
<li class="toctree-l4"><a class="reference internal" href="#ls-stat">文件的 ls/stat 操作扩展了</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id2">巨型目录</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">硬链接</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id4">工作集的尺寸</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id5">你真的需要文件系统么？</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../fs-volumes/"> FS 卷和子卷</a></li>
<li class="toctree-l3"><a class="reference internal" href="../quota/"> CephFS 配额管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../health-messages/"> 健康消息</a></li>
<li class="toctree-l3"><a class="reference internal" href="../upgrading/">升级 MDS 集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../upgrading/#firefly-jewel">升级比 Firefly 老的文件系统，需过 Jewel 这个槛</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-top/"> CephFS Top 工具</a></li>
<li class="toctree-l3"><a class="reference internal" href="../snap-schedule/"> 定时快照</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-mirroring/"> CephFS 快照镜像</a></li>
<li class="toctree-l3"><a class="reference internal" href="../purge-queue/"> 清理队列</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id6">CephFS 内幕</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="id1">
<h1>分布式文件系统之上的应用程序最佳实践<a class="headerlink" href="#id1" title="Permalink to this heading"></a></h1>
<p>CephFS 与 POSIX 标准兼容的、所以它应该适用于使用 POSIX 文件系统的任意应用程序。然而，
由于它是一个网络文件系统（不像诸如 XFS 的）
并且是强一致性的（不像诸如 NFS 的），所以，
应用程序作者了解一下某些后果是有好处的。</p>
<p>下面几节描述了分布式文件系统与本地文件系统在性能表现上有明显差异的一些地方。</p>
<section id="ls-l">
<h2>ls -l<a class="headerlink" href="#ls-l" title="Permalink to this heading"></a></h2>
<p>当你运行 <code class="docutils literal notranslate"><span class="pre">ls</span> <span class="pre">-l</span></code> 命令时， <code class="docutils literal notranslate"><span class="pre">ls</span></code> 程序会先罗列目录、
然后对其内每一个文件调用一次 <code class="docutils literal notranslate"><span class="pre">stat</span></code> 。</p>
<p>这通常远超一个应用程序的真实需求，而且在大目录上会很慢。
如果你不是真的需要各文件的所有此类元数据，那就只用一个 <code class="docutils literal notranslate"><span class="pre">ls</span></code> 吧。</p>
</section>
<section id="ls-stat">
<h2>文件的 ls/stat 操作扩展了<a class="headerlink" href="#ls-stat" title="Permalink to this heading"></a></h2>
<p>如果另一个客户端当时正在要罗列的目录里扩充文件，
那么 <code class="docutils literal notranslate"><span class="pre">ls</span> <span class="pre">-l</span></code> 就需要特别长的时间才能完成，
因为罗列器必须等着写入器刷回数据之后，
它才能合法地读取每个文件的尺寸。所以，
除非你 <em>特别想</em> 知道目录里每个文件的确切尺寸，否则别做这种操作。</p>
<p>另一个节点在向文件追加时，这种问题同样适用于任何直接发出 <code class="docutils literal notranslate"><span class="pre">stat</span></code> 系统调用的应用程序代码。</p>
</section>
<section id="id2">
<h2>巨型目录<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p>你真的需要有 10,000,000 个文件的目录？
即便目录分片技术能让 CephFS 处理它，
和拆分成中等规模的很多目录相比，它总是低效的。</p>
<p>操作很大的目录时，即使是标准的用户空间工具也会变得很慢。
例如， <code class="docutils literal notranslate"><span class="pre">ls</span></code> 的默认行为是给出按字母顺序排列好的结果，
但是 <code class="docutils literal notranslate"><span class="pre">readdir</span></code> 系统调用给出的可不是排序好的结果
（一般来说是这样的，不止是 CephFS ）。
所以，当你 <code class="docutils literal notranslate"><span class="pre">ls</span></code> 一个有百万个文件的目录时，
它得把一百万个名字的列表加载进内存、排序列表、然后写出到显示器。</p>
</section>
<section id="id3">
<h2>硬链接<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>硬链接在内部管理上有个固有代价，
一个文件系统必须维护同一份数据的两个引用。
在 CephFS 文件系统中有特殊的性能代价，
因为普通文件的 inode 是嵌入在目录里的
（也就是，查找到路径后不会额外读取其它 inode ）。</p>
</section>
<section id="id4">
<h2>工作集的尺寸<a class="headerlink" href="#id4" title="Permalink to this heading"></a></h2>
<p>MDS 是作为 RADOS 里面元数据的缓存运作的。
工作载荷的元数据是否能装进缓存对元数据的性能影响非常大。</p>
<p>如果你的工作载荷文件太多，未必能全部装进缓存（用 <code class="docutils literal notranslate"><span class="pre">mds_cache_memory_limit</span></code> 选项配置），
那么确保你测试得没问题：不要用少量文件测试完系统，
就期望文件数巨大时也有差不多的性能。</p>
</section>
<section id="id5">
<h2>你真的需要文件系统么？<a class="headerlink" href="#id5" title="Permalink to this heading"></a></h2>
<p>记着， Ceph 还有对象存储接口。如果你的应用程序需要存储海量扁平文件，
而且都是一次读写整个文件，那么你可能更适合用 <a class="reference internal" href="../../radosgw/#object-gateway"><span class="std std-ref">对象网关</span></a> 。</p>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../nfs/" class="btn btn-neutral float-left" title="NFS" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../fs-volumes/" class="btn btn-neutral float-right" title="FS 卷和子卷" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>